Skip to content

Conversation

arichardson
Copy link
Member

No description provided.

@arichardson arichardson requested a review from qwattash April 22, 2025 19:08
@arichardson arichardson marked this pull request as draft April 22, 2025 19:30
@arichardson
Copy link
Member Author

Will try to fix the CI failures and then merge to main.


def setup(self):
super().setup()
self.make_args.set(FW_TEXT_START=0x80000000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be 0. It's built as a PIE if possible. The expectation is it self-relocates at startup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yes, from what I can tell this is in fact redundant. Removing it appears to be working correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heshamelmatary I think you needed that, do you know what relies on it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, I get an error like the following when using fw_jump.elf as QEMU's -bios:

qemu-system-riscv64cheri: Some ROM regions are overlapping
These ROM regions might have been loaded by direct user request or by default.
They could be BIOS/firmware images, a guest kernel, initrd or some other file loaded into guest memory.
Check whether you intended to load all this guest code, and whether it has been built to load to the correct addresses.

The following two regions overlap (in the memory address space):
/home/hesham/cheri/output/cheri-alliance-sdk/opensbi/riscv64/share/opensbi/l64pc128/generic/firmware/fw_jump.elf ELF program header segment 0 (addresses 0x0000000000000000 - 0x00000000000241c0)
mrom.reset (addresses 0x0000000000001000 - 0x0000000000001028)

QEMU's loader uses the segments' addresses when loading ELF bioses. It will work fine if we just use the binary versions rather than ELFs, but sometimes (e.g., when debugging or when we only have ELF loaders), we need to pass the bios/opensbi as an ELF.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think we discussed the error in chat but I forgot. I think I have never noticed this because the cheribuild run target always uses the binary image version. I think we are also only installing the binary version in the sdk directory, perhaps we should install also the ELF version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .bin file is the same as the .elf file, I don't understand why you'd ever need to pass the .elf file to QEMU instead (though I do personally believe that's the "nicer" thing to pass). Just because QEMU is given the .bin file doesn't mean you can't give the debugger the .elf.

But yes, it seems QEMU, like many things, forgets PIEs exist in its ELF loader.

Copy link
Contributor

@qwattash qwattash Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference. riscv-software-src/opensbi#372
Which I think has been merged here qemu/qemu@55c1365

@qwattash
Copy link
Contributor

qwattash commented Aug 7, 2025

Will try to fix the CI failures and then merge to main.

I added a WIP commit that points the cheri-alliance-llvm to a repository that currently works for us. I think this should not be merged until we have a good "official" llvm to point this to.

qwattash and others added 15 commits August 8, 2025 11:51
Otherwise it'll link to 0x0.

Co-authored-by: Hesham Almatary <[email protected]>
Imitate morello-llvm to build CHERI Alliance's LLVM and QEMU
for --riscv-cheri-isa std. This only applies to CHERI-RISC-V.
Depending on ISA switch --riscv-cheri-isa,use the appropriat SDK.
This is not currently supported by the Cheri Allliance LLVM.
Also delete unused Alliance target class
CI fails otherwise with an error:

Traceback (most recent call last):
  File "<stdin>", line 22514, in <module>
  File "<stdin>", line 22851, in BuildCheriseL4Excercises
NameError: name 'BuildAllianceOpenSBI' is not defined
Propagate the current CheriConfig depending whether the llvm_project
is queried during early dependency resolution or during Project
initialization.
This is similar to temporary_url_override for GitRepository, but
introduces the temporary_branch_override argument that overrides the
default branch.
Temporarily point the default branch of the cheri-alliance-llvm to a
private repository with the latest rebased branch.
This is necessary to build CheriBSD.
Copy link
Member Author

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -84,8 +84,12 @@ def get_qemu_mfs_root_kernel(self, use_benchmark_kernel: bool) -> Path:

@functools.lru_cache(maxsize=20)
def _linker_supports_riscv_relaxations(linker: Path, config: CheriConfig, xtarget: "CrossCompileTarget") -> bool:
if xtarget.is_hybrid_or_purecap_cheri():
# XXX-AM: Hack: codasip lld does not seem to play nice with -mrelax and cheri
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But CHERI is already handled by the existing code. All this does is change the plain RISC-V flags?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will revert this, I also think it is redundant.

…flags.

When selecting supported linker relaxations, double check that xtarget is
a risc-v target before using the riscv_cheri_isa flag.
This is necessary to cross build binaries that work with c18n in CheriBSD.
This ignores -Wmissing-template-arg-list-after-template-kw.
Only enable flags when building for pure-capability targets.
@arichardson
Copy link
Member Author

@qwattash once you are happy with this and CI passes, please feel free to merge.

@arichardson arichardson marked this pull request as ready for review September 9, 2025 16:19
When building on aarch64 hosts, mtree's entry returns None in
--pretend mode.
New project to build and test CHERI Exercises running on CHERI-seL4 microkernel
and its CHERI-Microkit userspace.
@@ -342,7 +342,12 @@ def add_from_mtree(
if strip_binaries:
# Try to shrink the size by stripping all elf binaries
entry = self.mtree.get(mtree_path)
if entry is None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change seems wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit says that it's because when using --pretend the result here is None. @heshamelmatary
Is there a particular problem with this? @arichardson

@arichardson
Copy link
Member Author

@qwattash once you are happy with this and CI passes, please feel free to merge.

Opened #435 which has some extra fixes.

@arichardson arichardson marked this pull request as draft September 17, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants